import java.util.Map;
import java.util.PriorityQueue;

class KthLargest {
    public PriorityQueue<Integer> queue = new PriorityQueue<>();
    public int size = 0;

    public KthLargest(int k, int[] nums) {
        this.size = k;
        for(int x : nums){
            queue.offer(x);
            if(queue.size() > this.size){
                queue.poll();
            }
        }
    }

    public int add(int val) {
        queue.offer(val);
        if(queue.size() > size){
            queue.poll();
        }
        return queue.peek();
    }
}

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest obj = new KthLargest(k, nums);
 * int param_1 = obj.add(val);
 */